using System;
using System.Collections.Generic;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace SmlEngine.Sprites.Collections
{
    public abstract class SpriteCollection : IVisibility
    {
        public SpriteSet<Sprite> Sprites { get; private set; }
        public SpriteSet<StaticSprite> StaticSprites { get; private set; }

        public Vector2 Position { get; set; }
        public Vector2 Velocity { get; set; }
        public Vector2 Acceleration { get; set; }

        public Visibility Visibility { get; set; }

        protected SpriteCollection()
        {
            Sprites = new SpriteSet<Sprite>();
            StaticSprites = new SpriteSet<StaticSprite>();
        }

        public virtual void Update(GameTime gameTime)
        {
            Velocity += Acceleration * gameTime.GetElapsedSeconds();
            Position += Velocity * gameTime.GetElapsedSeconds();

            if (Visibility.IsActive())
            {
                foreach (Sprite sprite in Sprites)
                {
                    sprite.Update(gameTime);
                }
            }
        }

        public virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if (Visibility.IsVisible())
            {
                foreach (Sprite sprite in Sprites)
                {
                    sprite.Draw(gameTime, spriteBatch);
                }

                foreach (StaticSprite sprite in StaticSprites)
                {
                    sprite.Draw(spriteBatch);
                }
            }
        }
    }
}

